/*
 *接口编写处...
*如果接口需要做Action的权限验证，请在Action上使用属性
*如: [ApiActionPermission("upper_tool",Enums.ActionPermissionOptions.Search)]
 */
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using VOL.Entity.DomainModels;
using VOL.System.IServices;
using VOL.Core.EFDbContext;
using VOL.Core.Enums;
using VOL.Core.Filters;
using Microsoft.AspNetCore.SignalR;
using VOL.WebApi.Controllers.Hubs;

namespace VOL.System.Controllers
{
    public partial class upper_toolController
    {
        private readonly Iupper_toolService _service;//访问业务代码
        private readonly IHttpContextAccessor _httpContextAccessor;
        IHubContext<ToolStatusHub> _hubContext;

        [ActivatorUtilitiesConstructor]
        public upper_toolController(
            Iupper_toolService service,
            IHttpContextAccessor httpContextAccessor,
            IHubContext<ToolStatusHub> hubContext
        )
        : base(service)
        {
            _service = service;
            this._hubContext = hubContext;
            _httpContextAccessor = httpContextAccessor;
        }

        [HttpPost, Route("ChangeToolStatus")]
        [ApiActionPermission(ActionPermissionOptions.Update)]
        public ActionResult<int> ChangeToolStatus(int id,int location,int status)
        {
            var result = _service.ChangeToolStatus(id,location, status);
            if (result!=-1)
            {
                _hubContext.Clients.All.SendAsync("Ruku", status + "&" + id+"&"+location);
            }
            return result;
        }
    }
}
